package com.bee.health;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;
/**
 * 1.获取gridview，为他填充数据
 * 1.1也就是adapter
 * 1.2为item设置点击事件
 * @author bee
 *
 */
public class HomeActivity extends Activity {
	protected static final String TAG = "HomeActivity";
	private GridView list_home;
	private MyAdapter adapter;
	

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_home);
		
		list_home=(GridView) findViewById(R.id.list_home);
		adapter=new MyAdapter();
		//设置布局
		list_home.setAdapter(adapter);
		//设置item的单击事件
		list_home.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				Intent intent;
				switch (position) {
				case 0:
					//打开手机防盗
					intent=new Intent(HomeActivity.this,StepestimateActivity.class);
					startActivity(intent);
					break;
				case 1:
					//打开高级中心
					intent=new Intent(HomeActivity.this,StepCountActivity.class);
					startActivity(intent);
					break;
				case 2:
					//打开软件管理
				    intent=new Intent(HomeActivity.this,DistanceActivity.class);
					startActivity(intent);
					break;
			/*	case 3:
					//打开软件管理
				    intent=new Intent(HomeActivity.this,SleepActivity.class);
					startActivity(intent);
					break;*/
			/*case 3:
					//打开软件管理
				    intent=new Intent(HomeActivity.this,HeartrateActivity.class);
					startActivity(intent);
					break;*/
				case 3:
					//打开软件管理
				    intent=new Intent(HomeActivity.this,SportplanActivity.class);
					startActivity(intent);
					break;
				case 4:
					//打开软件管理
				    intent=new Intent(HomeActivity.this,MotiontrailActivity.class);
					startActivity(intent);
					break;
				
				default:
					break;
				}
			}
		});
	}
	
	private static String [] names = {
		"步态评估","步数","距离",
		//"睡眠质量","心率",
		"运动规划","运动轨迹"
		
	};
	
	private static int[] ids = {
		R.drawable.safe2,R.drawable.callmsgsafe1,R.drawable.app1,
	   // R.drawable.netmanager,R.drawable.trojan,
		R.drawable.sysoptimize1,R.drawable.settings1
		
	};
	private class MyAdapter extends BaseAdapter{

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return names.length;//这是数据库
		}



		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return null;
		}


		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return 0;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			View view=View.inflate(HomeActivity.this, R.layout.list_item_home, null);
			//在这个布局中找到相应的对象
			ImageView iv_item=(ImageView) view.findViewById(R.id.iv_item);
			TextView tv_item=(TextView) view.findViewById(R.id.tv_item);
			//把值设置进去
			tv_item.setText(names[position]);
			iv_item.setImageResource(ids[position]);
			return view;
		}


	}
	

}
